import request from '@/config/axios';
import { baseUrl } from '@/config/env';
/**
 * 获取用户的所有菜单
 */
export function getMenu(parentId =-1,type = "left") {
  return request({
    url: baseUrl+'/sys/menu/user',
    method: 'get',
   params: {
     type,
     parentId
   }
  })
}
/**
 * 获取用户的所有顶部菜单
 */
export function getTopMenu() {
  return request({
    url: baseUrl+'/sys/menu/user',
    method: 'get',
    params: {type: 'top'},
  })
}

/**
 * 获取角色所有的菜单
 */
export function fetchMenuByRoleId(roleId) {
  return request({
    url: baseUrl+'/sys/menu/role/' + roleId,
    method: 'get'
  })
}

/**
 * 获取所有的菜单
 */
export function fetchMenuTree(params) {
  return request({
    url: baseUrl+'/sys/menu/tree',
    method: 'get',
    params: params
  })
}

export function getObj(id) {
  return request({
    url: baseUrl+'/sys/menu/' + id,
    method: 'get'
  })
}

export function addObj(obj) {
  return request({
    url: baseUrl+'/sys/menu',
    method: 'post',
    data: obj
  })
}

export function putObj(obj) {
  return request({
    url: baseUrl+'/sys/menu',
    method: 'put',
    data: obj
  })
}

export function delObj(id) {
  return request({
    url: baseUrl+'/sys/menu/' + id,
    method: 'delete'
  })
}
